package com.zygh.lz.controller;

import com.zygh.lz.entity.Section;
import com.zygh.lz.service.SectionService;
import com.zygh.lz.stapprove.ResultUtil;
import com.zygh.lz.stapprove.SysPcLog;
import com.zygh.lz.vo.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "部门类", description = "SectionController")
public class SectionController {
    @Autowired
    private SectionService sectionService;

    @ApiOperation("新增部门")
    //@PostMapping("addSection")
    @SysPcLog(module = "新增部门",operation = "新增")
    public ResultBean addSection(@RequestBody Section section) {
        return sectionService.addSection(section);
    }

    @ApiOperation("修改部门")
    //@PostMapping("modefiSectionById")
    @SysPcLog(module = "修改部门",operation = "修改")
    public ResultBean modefiSectionById(@RequestBody Section section) {
        return sectionService.modefiSectionById(section);
    }

    @ApiOperation("根据id删除部门")
    //@GetMapping("delSectionById")
    @SysPcLog(module = "根据id删除部门",operation = "删除")
    public ResultBean delSectionById(Integer id) {
        return sectionService.delSectionById(id);
    }


    @ApiOperation("按层级推送")
    @GetMapping("selectAllSection")
    public ResultBean selectAllSection(String sectionname) {
        return sectionService.selectAllSection(sectionname);
    }

    @ApiOperation("查询所有部门")
    @GetMapping("selectSection")
    public ResultBean selectSection(String sectionname) {
        return sectionService.selectAllSectionInfo(sectionname);
    }

    //门人员信息查询那里的模糊查询
    @GetMapping("selectSectionByCt")
    public ResultBean selectSectionByCt(String sex, String staffHierarchy, String sectionName) {
        return sectionService.selectSectionByCt(sex, staffHierarchy, sectionName);
    }

    //根据部门id查询所有部门人员
    @GetMapping("selectBySectionId")
    public ResultBean selectBySectionId(Integer sectionId, String staffHierarchy) {
        return sectionService.selectBySectionId(sectionId, staffHierarchy);
    }

    //根据大队id查询大队下面的中队
    @GetMapping("selectDetachmentByid")
    public ResultBean selectDetachmentByid(Integer id) {
        return sectionService.selectDetachmentByid(id);
    }

    //部门层级列表
    @GetMapping("findSectionByTier")
    @ApiOperation("部门层级列表")
    public ResultBean findSectionByTier(String sectionname) {
        return sectionService.findSectionByTier(sectionname);
    }


    @ApiOperation("漏签统计模块大队条件展示")
    @GetMapping("findSectionByid")
    public ResultBean findSectionByid(Integer id) {
        return sectionService.findSectionByid(id);
    }

    @ApiOperation("消息管理模块部门层级列表")
    @GetMapping("findSectionTier")
    public ResultBean findSectionTier(Integer id) {
        return sectionService.findSectionTier(id);
    }


    @ApiOperation("在线统计部门列表")
    @GetMapping("findSectionTiers")
    public ResultBean findSectionTiers(Integer id) {
        return sectionService.findSectionTiers(id);
    }


    @ApiOperation(value = "获取所有部门列表")
    @GetMapping("getSectionTree")
    public ResultBean getSectionTree(Integer id) {
        return sectionService.getSectionTree(id);
    }

    @ApiOperation(value = "勤务部署，日常勤务，按条件搜索")
    @GetMapping("/findByCondition")
    public ResultBean findByCondition(@ApiParam(name="postCode", value = "岗位类型")
                                      @RequestParam(required = false, value = "postCode") Integer postCode,
                                      @ApiParam(name = "sectionIds",value = "单位id数组")
                                      @RequestParam(required = false, value ="sectionIds" ) int[] sectionIds,
                                      @ApiParam(name = "gridding", value = "岗位名称")
                                      @RequestParam(required = false, value = "gridding") String gridding) {
        return sectionService.findByCondition(postCode, sectionIds, gridding);
    }

    @ApiOperation(value = "根据岗位id查询签到人员信息")
    @GetMapping("/getByPostId/{id}")
    public ResultBean getByPostId(@ApiParam(name = "id", value = "岗位id")
                                  @PathVariable("id") Integer id) {
        return sectionService.getByPostId(id);
    }


    @ApiOperation(value = "获取所有部门列表,到支队")
    @GetMapping("getSectionAll")
    public ResultBean getSectionAll(Integer id) {
        return sectionService.getSectionAll(id);
    }

    @ApiOperation(value = "获取数据统计配置部门列表")
    @GetMapping("selectSectionByPid")
    public ResultBean selectSectionByPid() {
        return sectionService.selectSectionByPid();
    }

    @ApiOperation(value = "首页警力分类部门列表")
    @GetMapping("findSectionsByPid")
    public ResultBean findSectionsByPid(Integer pid) {
        return ResultUtil.setOK("success", sectionService.findSectionsByPid(pid));
    }


    @ApiOperation("批量修改部门")
    @GetMapping("batckSectionById")
    @SysPcLog(module = "批量修改部门",operation = "修改")
    public ResultBean batckSectionById(int[] id) {
        List<Section> list = sectionService.list();
        for (Section section : list) {
            section.setIsCheck(0);
            sectionService.updateSectionByIds(section);
        }

        Section section = new Section();
        for (int i : id) {
            section.setSysSectionId(i);
            section.setIsCheck(1);
            sectionService.updateSectionByIds(section);
        }
        return ResultUtil.setOK("success", null);
    }


}

